package cn.medemede.servlet.action;


import cn.medemede.dao.UserpwdDao;
import cn.medemede.model.Authority;
import cn.medemede.model.UserpwdBean;
import cn.medemede.model.UsersBean;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.PrintWriter;
import java.util.ArrayList;

public class StuDel implements Action {
    @Override
    public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");
        HttpSession session = request.getSession();
        String farward=null;
        if(((Authority)session.getAttribute("character")).getDel()) {
            PrintWriter out = response.getWriter();
            ArrayList<UsersBean> stulist = (ArrayList<UsersBean>) session.getAttribute("stulist");
            int stuid = Integer.parseInt(request.getParameter("stuid"));
            UsersBean usersBean = stulist.get(stuid);
            if (UserpwdDao.remove(usersBean.getUsername())) {
                System.out.println("删除成功！");
                farward = "delSuc";
            }
        }
        return farward;
    }
}
